package cn.initcap.authentication;

import cn.initcap.domain.Admin;
import cn.initcap.repository.AdminRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;


/**
 * @author initcap
 * @date 2018/5/22 AM10:06
 */
@Component
@Transactional
@Slf4j
public class RbacUserDetailsService implements UserDetailsService {

    @Autowired
    private AdminRepository adminRepository;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        log.info("表单登录用户名:" + username);
        Admin admin = adminRepository.findByUsername(username);
        log.info(admin.toString());
        return admin;
    }

}
